<?php
/*
Plugin Name: Manage Parish and Catechism
Plugin URI: http://www.connectonline.in
Description: This plugin used to manage parish Info
Version: 1.0
Author: Selestin Thomas
Author URI: http://www.connectonline.in
*/


add_shortcode('other_services','other_services_func');
add_shortcode('order_form','order_form_func');
add_shortcode('listing_address','listing_address_func');
add_shortcode('user_details','user_details_func');
add_shortcode('manage_user', 'manage_user_func');
add_shortcode('specturm_package', 'specturm_package_func');
add_shortcode('list_orders', 'list_orders_func');
//add_shortcode('vmember_List', 'viewmember_list');


require_once("memberclass.php");
$objMem = new memberClass();

require_once("packageclass.php");
$objPkg = new packageClass();

require_once("serviceclass.php");
$objSrv = new serviceClass();

require_once("trackclass.php");
$objTrack = new trackClass();





require_once("serviceareaclass.php");
$objSrvAea = new serviceareaClass();

	# INTIAL CALL
	function addmyplug() {
		require_once(ABSPATH . "wp-admin/includes/upgrade.php");
		global $wpdb;
		
		# 1 spec_assigned_orders
		$table_name = $wpdb->prefix . "spec_assigned_orders";
		$MSQL = "show tables like '$table_name'";
		if($wpdb->get_var($MSQL) != $table_name)
		{
		  $sql = "CREATE TABLE IF NOT EXISTS $table_name  (
			  `id` int(21) NOT NULL AUTO_INCREMENT,
			  `order_id` int(21) NOT NULL,
			  `assigned_by` int(21) NOT NULL,
			  `assigned_to` int(21) NOT NULL,
			  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
			  PRIMARY KEY (`id`)
			)";
			dbDelta($sql);
		}
		
		# 2 spec_authorise
		
		# 3 spec_checkout
		$table_name = $wpdb->prefix . "spec_checkout";
		$MSQL = "show tables like '$table_name'";
		if($wpdb->get_var($MSQL) != $table_name)
		{
		  $sql = "CREATE TABLE IF NOT EXISTS $table_name (
				  `id` int(21) NOT NULL AUTO_INCREMENT,
				  `user_id` int(21) NOT NULL,
				  `listing_add_id` int(21) NOT NULL,
				  `package_ids` varchar(100) NOT NULL,
				  `total_amount` varchar(21) NOT NULL,
				  `payment_status` int(21) NOT NULL,
				  `payment_message` text NOT NULL,
				  `payment_time` varchar(21) NOT NULL,
				  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
				  PRIMARY KEY (`id`)
				)";
			dbDelta($sql);
		}
		
		# 4 spec_listing_address
		$table_name = $wpdb->prefix . "spec_listing_address";
		$MSQL = "show tables like '$table_name'";
		if($wpdb->get_var($MSQL) != $table_name)
		{
		  $sql = "CREATE TABLE IF NOT EXISTS $table_name (
				  `id` int(4) NOT NULL AUTO_INCREMENT,
				  `brokerage` varchar(100) NOT NULL,
				  `agent_name` varchar(21) NOT NULL,
				  `agent_email` varchar(100) NOT NULL,
				  `agent_phone` varchar(100) NOT NULL,
				  `property_address` text NOT NULL,
				  `description` text NOT NULL,
				  `unit_number` varchar(100) NOT NULL,
				  `sq_footage` varchar(100) NOT NULL,
				  `bed_bath` VARCHAR( 21 ) NOT NULL,
				  `faces` varchar(100) NOT NULL,
				  `user_id` int(21) NOT NULL,
				  PRIMARY KEY (`id`)
				)";
			dbDelta($sql);
		}
		
		# 5 spec_messages
		$table_name = $wpdb->prefix . "spec_messages";
		$MSQL = "show tables like '$table_name'";
		if($wpdb->get_var($MSQL) != $table_name)
		{
		  $sql = "CREATE TABLE IF NOT EXISTS $table_name (
				  `id` int(21) NOT NULL AUTO_INCREMENT,
				  `added_by` int(21) NOT NULL,
				  `send_to` int(21) NOT NULL,
				  `track_id` int(21) NOT NULL,
				  `message` text NOT NULL,
				  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				  `entered_time`varchar(21) NOT NULL,
				  `read_status` tinyint(4) NOT NULL,
				  PRIMARY KEY (`id`)
				)";
			dbDelta($sql);
		}
		
		# 6 spec_order_trac
		
		$table_name = $wpdb->prefix . "spec_order_trac";
		$MSQL = "show tables like '$table_name'";
		if($wpdb->get_var($MSQL) != $table_name)
		{
		  $sql = "CREATE TABLE IF NOT EXISTS $table_name(
				  `id` int(21) NOT NULL AUTO_INCREMENT,
				  `order_id` int(21) NOT NULL,
				  `track_status` int(21) NOT NULL,
				  `assigned_user` int(11) NOT NULL,
				  `photoshoot_time` varchar(21) NOT NULL,
				  PRIMARY KEY (`id`)
				)";
			dbDelta($sql);
		}

		# 7 spec_package
		$table_name = $wpdb->prefix . "spec_package";
		$MSQL = "show tables like '$table_name'";
		if($wpdb->get_var($MSQL) != $table_name)
		{
		  $sql = "CREATE TABLE IF NOT EXISTS $table_name (
				`id` int(21) NOT NULL AUTO_INCREMENT,
				 `name` varchar(50) NOT NULL,
				 `description` text NOT NULL,
				 `type` varchar(21) NOT NULL,
				 `terms` text NOT NULL,
				 `link` text NOT NULL,
				 `status` tinyint(4) NOT NULL,
				 `price` varchar(100) NOT NULL,
				 PRIMARY KEY (`id`)
			) ";
			dbDelta($sql);
		}
		
		
		
		
		# 8 spec_service_area
		$table_name = $wpdb->prefix . "spec_service_area";
		$MSQL = "show tables like '$table_name'";
		if($wpdb->get_var($MSQL) != $table_name)
		{
		  $sql = "CREATE TABLE IF NOT EXISTS $table_name (
				 	`id` int(21) NOT NULL AUTO_INCREMENT,
				 	`zip` varchar(21) NOT NULL,
				 	`status` int(21) NOT NULL,
				 	 PRIMARY KEY (`id`)
			) ";
			dbDelta($sql);
		}
		
		# 9 spec_tours
		$table_name = $wpdb->prefix . "spec_tours";
		$MSQL = "show tables like '$table_name'";
		if($wpdb->get_var($MSQL) != $table_name)
		{
		  $sql = "CREATE TABLE IF NOT EXISTS $table_name (
				 	`id` int(11) NOT NULL AUTO_INCREMENT,
					`url` text NOT NULL,
					`image` varchar(100) NOT NULL,
					`status` int(11) NOT NULL,
				 	 PRIMARY KEY (`id`)
			) ";
			dbDelta($sql);
		}
		# CREATE A NEW USER TYPE
		$result = add_role(
				'customer',
				__( 'Customer' ),
				array(
					'read'         => true,  // true allows this capability
				)
			);
		$result = add_role(
				'photographer',
				__( 'Photographer' ),
				array(
					'read'         => true,  // true allows this capability
					
				)
			);	
		$result = add_role(
				'designer',
				__( 'Designer' ),
				array(
					'read'         => true,  // true allows this capability
					
				)
			);
	}
	/* Hook Plugin */
	register_activation_hook(__FILE__,'addmyplug');
	/* Creating Menus */
	function member_Menu()
	{

			
	/*add_menu_page( 'myplug/muyplg123.php', 'Students', 'manage_options', 'admin.php?page=memberlist&type=students', '','', 20); 
	add_submenu_page('myplug/muyplg123.php', 'memberlist', 'memberlist', 10, 'memberlist', 'memberlist');
	add_menu_page( 'myplug/muyplg123d.php', 'Manage Staff', 'manage_options', 'admin.php?page=memberlist&type=photographers', '','', 11 ); 
		 
		 
		 
	add_menu_page( 'Chatechim', 'Chatechim', 'manage_options', 'admin.php?page=reports', '','', 12 ); 
	add_menu_page( 'Parishner', 'Parishner', 'manage_options', 'admin.php?page=parishner', '','', 13 ); 
	add_submenu_page('admin.php?page=memberlist', 'memberlist', 'memberlist', 10, 'admin.php?page=memberlist', 'memberlist');
	add_submenu_page('', 'Add member', 'Add member', 5, 'member_add', 'member_add');
	
	
	

	
	
	
	
	add_submenu_page('', 'memberlist', 'export_to_exl', 5, 'export_to_exl', 'export_to_exl');
	add_submenu_page('', 'Add Package', 'Add Package', 5, 'package_add', 'package_add');
	
	add_submenu_page('', 'Add Service', 'Add Service', 5, 'service_add', 'service_add');
	add_submenu_page('', 'Add Service Area', 'Add Service Area', 5, 'service_area_add', 'service_area_add');
	add_submenu_page('', 'Update Status', 'Edit Status', 5, 'edit_track', 'edit_track');
	add_submenu_page('', 'Order details', 'Order details', 5, 'order_more_info', 'order_more_info');
	add_submenu_page('', 'List Service Area ', 'List Service Area', 5, 'service_area_list', 'service_area_list');
		
	add_submenu_page('',  'Track the order','Order Tracking', 5, 'order_tracking', 'order_tracking');
	
	add_submenu_page('', 'Payment Reports', 'Reports', 5, 'reports', 'reports');
		add_submenu_page('', 'Payment Reports', 'Reports', 5, 'parishner', 'parishner');
		add_options_page('Authorize.net', 'Authorize.net', 'manage_options', 'my-plugin.php', 'authorize_settings');
		add_options_page('Service Area', 'Service Area', 'manage_options', '', 'service_area_list'); */
		// ///////////////////////////////////////////////
		add_menu_page('Catchism','Catchism', 5,'myplug/muyplg.php', 'students_list');
		add_submenu_page('myplug/muyplg.php', 'List Services', 'Promotion List', 5, 'service_list', 'reports');
		# PERMISSION ISSUE
		add_submenu_page('', 'Order details', 'Order details', 5, 'order_more_info', 'order_more_info');
		add_submenu_page('', 'Order details', 'Order details', 5, 'memberlist', 'memberlist');
		add_submenu_page('', 'Add member', 'Add member', 5, 'member_add', 'member_add');

		
		add_menu_page('Parishner','Parishner',6,'new', 'parishner');
		add_submenu_page('new', 'Family', 'Family', 6, 'family', 'family');


		wp_register_style('demo_table.css', plugin_dir_url(__FILE__) . 'css/demo_table.css');
		wp_enqueue_style('demo_table.css');
	
		wp_register_script('jquery.dataTables.js', plugin_dir_url(__FILE__) . 'js/jquery.dataTables.js', array('jquery'));
		wp_enqueue_script('jquery.dataTables.js');

	}

	add_action('admin_menu', 'member_Menu');
	
	
	function students_list() {
	
		$type   = 'students'; 
		include "memberlist.php";
	}	
	
	
	function memberlist() {
		include "memberlist.php";
	}

	function authorize_settings() {
		include "authorize_settings.php";
	}
	function service_list(){
		include "service_list.php";
		}
	function order_tracking(){
		include "order_tracking.php";
		}	
	function service_area_list(){
		include "service_area_list.php";
		}	
	function package_list() {
		include "packagelist.php";
	}
	function payment_details() {
		include "payment_details.php";
	}
	function reports() {
		include "reports.php";
	}
	
	function parishner(){
		include "parishner.php";

	}
	
	function family(){
		include "family.php";

	}
	
	function member_add() {
	include "member-new.php";
	}
	
	
	function service_add() {
		include "service_add.php";
	}
	function service_area_add(){
		include "service_area_add.php";
	}
	
	function edit_track(){
	include "edit_track.php";
	}	
	
	function order_more_info(){
	include "order_more_info.php";	
		}
		
	function package_add() {
		include "package-new.php";
	}
	function export_to_exl(){
	
	
$columns_Arr[] = array($accoutingnumber=1,$insname=2,$companyname=3,$adjustercompany=4,$refetype=5,$referral_name=6,$refsource_name=7,$program_name=8);	
		
				$filename = "Cleanupsheet.csv";
				header("Content-type: application/octet-stream\n");
				header("Content-disposition: attachment; filename=\"$filename\"\n");		
				header("Content-transfer-encoding: binary\n");
							
				for($i=0; $i < count($columns_Arr); $i++){
					$data_arr = "";
					$header = "";
					foreach($columns_Arr[$i] as $key=>$value){					
						if($i == 0){
							if(is_array($value)){
								foreach($value as $field=>$val){
									$header .= '"'.trim($field).'",';
								}
							}							
						}
						if(is_array($value)){
							foreach($value as $field=>$val){
								$data_arr .= '"' . $val . '",';
							}
						}					
						$data_arr .=  '"'. $value  .'",';						
					}
					if($i==0){
						echo $header . 'JOB,INSURED NAME,INSURANCE COMPANY,INDEP.ADJUSTER COMPANY,REF.TYPE,REF.NAME,REF.SOURCE,PROGRAM'. "\n";

					}
					rtrim($data_arr,",");
					echo $data_arr . "\n";
				}
				exit;
	
	}
	if(isset($_POST['assign_project'])){
		$table = $wpdb->prefix . "spec_order_trac";
		if($_POST["addme"] == "2")
		{
			$assigned_by = 1;
			$order_id    = $_POST['order_id']; 
			$assigned_to = $_POST['assigned_user'];
			# Assign to PHOTOGRAPHER
			if($assigned_to!='')
			$objTrack->assign_project($assigned_by,$assigned_to,$order_id,$track_status=2);
			
			# Assign to Designer
			$project_designer = $_POST['project_designer'];
			if($project_designer!='')
			$objTrack->assign_photographer($assigned_by,$project_designer,$order_id);
			/*echo '<script>
						 opener.location.reload(); // or opener.location.href = opener.location.href;
						 window.close();
				</script>';
				exit;*/
			
			header("Location:admin.php?page=edit_track&act=upd&id=".$order_id."");
			//exit;
		}
		
	}
	if(isset($_POST['reassign_project'])){
	
		 $reassgned_photographer = $_POST['reassgned_photographer'];
		 $reassgned_designer	 = $_POST['reassgned_designer'];
		 $order_id      		 = $_POST['order_id_reassign'];
		 $old_designer			 = $_POST['old_designer'];
		 $old_photographer       = $_POST['old_photographer'];
		
		$objTrack->reassignProject($order_id,$reassgned_photographer,$old_photographer);
		$objTrack->reassignProject($order_id,$reassgned_designer,$old_designer);
		echo '<script>
						 opener.location.reload(); // or opener.location.href = opener.location.href;
						 window.close();
				</script>';
				exit;
	
	}
	if(isset($_POST['submit_track'])){
		$table = $wpdb->prefix . "spec_order_trac";
		if($_POST["addme"] == "2")
		{
			
			$objTrack->updtrack($table_name = $table,$_POST,$profile_picture);
			$assigned_to = $_POST['assigned_user'];
			$assigned_by = 1;
			$order_id    = $_POST['order_id']; 
			
			
			
			# Assign to PHOTOGRAPHER
			if($assigned_to!='')
			$objTrack->assign_project($assigned_by,$assigned_to,$order_id,$_POST['track_status']);
			
			# Assign to Designer
			$project_designer = $_POST['project_designer'];
			if($project_designer!='')
			$objTrack->assign_photographer($assigned_by,$project_designer,$order_id);
			
			# Message to Customer
			$entered_time = time();
			$track_message	= $_POST['track_message'];
			$user_id 			= $_POST['user_id'];
			$track_status		= $objTrack->getTrackStatus($_POST['track_status']);
			
			$message_customer= $track_status;
			if(isset($message_customer))
			$message_customer.='<br><br>'.$track_message;
			
			if(isset($message_customer)){
				$objTrack->saveMessage($assigned_by,$user_id,$order_id,$message_customer,$entered_time);
			}
			if($track_message!=''){
				
				$objTrack->send_mail_track($user_id,$subject,$message_customer,$headers,$attachments,$assigned_by,$order_id,$mailtype='customer_status_update');
			}
						
			# Message to Assigned
			$message_for_assigned = $_POST['message_for_assigned'];
			if(isset($message_for_assigned)){
				$objTrack->saveMessage($assigned_by,$assigned_to,$order_id,$message_for_assigned,$entered_time);
			}
			$objTrack->send_mail_track($assigned_to,$subject,$message_for_assigned,$headers,$attachments,$assigned_by,$order_id,$mailtype='assign_project');
			
			echo '<script>
						 opener.location.reload(); // or opener.location.href = opener.location.href;
						 window.close();
				</script>';
				exit;
			
			//header("Location:admin.php?page=order_tracking&info=upd");
			exit;
		}
	}
	
	if(isset($_POST["submit_package"]))
	{	
		$table = $wpdb->prefix . "spec_package";
		if($_POST["addme"] == "1")
		{	$objPkg->addNewPackage($table_name = $table,$_POST,$profile_picture);
			header("Location:admin.php?page=myplug/muyplg.php&info=saved");
			exit;
		}
		else if($_POST["addme"] == "2")
		{
			$objPkg->updPackage($table_name = $table,$_POST,$profile_picture);
			header("Location:admin.php?page=myplug/muyplg.php&info=upd");
			exit;
		}
	}
	
	if(isset($_POST['submit_service'])){
		
		$table = $wpdb->prefix . "spec_package";
		if($_POST["addme"] == "1")
		{	
		$objSrv->addNewservice($table_name = $table,$_POST,$profile_picture);
			header("Location:admin.php?page=service_list&info=saved");
			exit;
		}
		else if($_POST["addme"] == "2")
		{
			$objSrv->updservice($table_name = $table,$_POST,$profile_picture);
			header("Location:admin.php?page=service_list&info=upd");
			exit;
		}
	}

	# submit_service_area
	if(isset($_POST['submit_service_area'])){
		
		$table = $wpdb->prefix . "spec_service_area";
		if($_POST["addme"] == "1")
		{	
		$objSrvAea->addNewserviceArea($table_name = $table,$_POST,$profile_picture);
			header("Location:admin.php?page=service_area_list&info=saved");
			exit;
		}
		else if($_POST["addme"] == "2")
		{
			$objSrvAea->updserviceArea($table_name = $table,$_POST,$profile_picture);
			header("Location:admin.php?page=service_area_list&info=upd");
			exit;
		}
	}
	
 ################################################################# FROND end ############################################
 
 	function other_services_func(){
		
		$table.='<h1>Other Services</h1>';	
		$query_cart = mysql_query('SELECT * FROM wp_spec_package WHERE type="Service"');
			if (mysql_num_rows($query_cart) > 0 )
			{
				while ($row = mysql_fetch_assoc($query_cart))
				{
					$id      	  = $row['id'];
					$name 		  = $row['name'];
					$description  = $row['description'];
					$price		  = $row['price']; 
					
					$table.='<div class="col-lg-10 services_DetailsBlock">
								<table class="table col-lg-12" >
								  <tbody>
									<tr>
									  <td align="left" valign="top" class="col-lg-8 text-left">
									 <div style="float:left; margin-top:0 !important; padding:0 !important;"> <h3 style="margin:0; padding:0; float:left;">'.$name.'</h3>
										<p class="text-left">'.$description.'</p>
									   </div>
										</td>
									  <td class="col-lg-2 col-md-2 col-sm-2 col-xs-3 text-center priceTableBlock"><div  class="price_round price_round_light"><span>$'.$price.'</span></div></td>
									  <td align="center" valign="top" class="col-lg-2  col-md-2 col-sm-2 col-xs-3 text-center"><div>
									  <form class="addToCartBtnForm" action="'.get_site_url().'/list-of-specturm-orders" method="post">
									<input type="hidden" name="package" value="'.$id .'" />
									<input type="hidden" name="id" value="'.$id .'" />
								<input class="btn btn-md btn-warning" type="submit" value="Add Service" name="submit" /></form>
									 </div></td>
									</tr>
								  </tbody>
								</table>
								<div class="clearfix"></div>
							  </div>';
					
					
				}
			}		
			
			
			return $table;}
	# DISPLAY PACKAGE
 	function specturm_package_func($id) {
	 	$status = '';
	    $sql = "SELECT * FROM wp_spec_package WHERE id = ".$id[0]." ";
		$result = mysql_query($sql) or die ('Error, query failed');
		if (mysql_num_rows($result) > 0 )
		{
			while ($row = mysql_fetch_assoc($result))
			{
				$id      	  = $row['id'];
				$name 		  = $row['name'];
				$description  = $row['description'];
				$terms		  = $row['terms'];  
				$price		  = $row['price']; 
			}
		}
	    $wb_outHTML = '
		<h3 class="widget-title">'.$name.'</h3>
  		<div class="textwidget">	'.$description.'	
		<ul class="spectrum_pkg"> 
					'.$terms.'
				</ul>
				 <span class="price_round price_round_medium">$'.$price.'</span> 
				 	<form action="'.get_site_url().'/list-of-specturm-orders" method="post">
						<input type="hidden" name="package" value="'.$id .'" />
						<input type="hidden" name="id" value="'.$id .'" />
						<input class="btn btn-lg btn-default btn-warning" type="submit" value="ORDER NOW" name="submit" />
				</form> 
				';			
	 return $wb_outHTML;
 }
 

 	# LIST ORDERS
 	function list_orders_func(){
		error_reporting(0);
		 # ADD ITEM TO CART
		 if(isset($_REQUEST['id']))
			{
				
			if(isset($_SESSION['spec_cart']) && !empty($_SESSION['spec_cart']))
							{
								$array = $_SESSION['spec_cart'];
								if(!in_array($_REQUEST['id'], $array))
									$_SESSION['spec_cart'][]=$_REQUEST['id'];
							}
						else
							{
							$_SESSION['spec_cart']= array();
							$_SESSION['spec_cart'][]=$_REQUEST['id'];
							}
			}
	
		 # LIST CART ITEMS
		 if($_GET['listorders']=true){
		 if($_GET['rm']>0){
				foreach(($_SESSION['spec_cart']) as $k=>$v){
					if($v == $_GET['rm'])
  					  unset($_SESSION['spec_cart'][$k]);
				}
			 }
		 
		 
		 
		 $table ='<h1>Order Form</h1>
					
						<div class="progressbarBlock">
							<ul class="progressbar">
								<li class="stage1"><img src="'.get_template_directory_uri().'/images/steps_1.png" class="img-responsive" /></li>
							</ul>
						</div>
		 
		 			<div id="shoppingCart_Wrapper">
					<h2>Shopping Cart</h2>
					<div class="clearfix"></div>
					<div class="table-responsive">
					<table class="table table-striped table-hover">
					<tr>
					<th class="col-lg-8 col-md-8">Package Name</th>
					<th class="col-lg-2 col-md-2 text-center">Remove Item</th>
					<th class="col-lg-2 col-md-2 text-center">Price</th>
					</tr>';
					$total_price = 0;
						foreach(($_SESSION['spec_cart']) as $package){
						$query_cart = mysql_query('SELECT * FROM wp_spec_package WHERE id ='.$package.'');
						if (mysql_num_rows($query_cart) > 0 )
						{
							while ($row = mysql_fetch_assoc($query_cart))
							{
								$id      	  = $row['id'];
								$name 		  = $row['name'];
								$description  = $row['description'];
								$terms		  = $row['terms'];  
								$price		  = $row['price']; 
								$total_price  = $total_price + $price;
								
							}
						}
							   
					 
						# LINK FOR REMOVE ITEM
						$params = array( 'listorders' => "true",'rm'=>$id );
						$item_remove = add_query_arg( $params, get_permalink() );	
						
						# LINK FOR CONTINUE 
						if(isset($_SESSION['user_ID'])){
							$continue_link = get_site_url().'/listing-address';}
						else{
							$params = array( 'rewrite_url' => "listing-address");
							$continue_link = add_query_arg( $params, get_site_url().'/login' );
							}
						//$table .='<tr><td>'.$name.'</td><td><a href="'.$item_remove.'">Remove</a></td><td>$'.$price.'</td></tr>';	
						
						$table .='<tr>
						<td>'.$name.'</td>
						<td class="col-lg-2 col-md-2 text-center">
							<a href="'.$item_remove.'"><img src="'.get_template_directory_uri().'/images/delete_icon.png"></a></td>
						<td class="col-lg-2 col-md-2 text-center">$'.$price.'</td>
						</tr>';
					    }
						
			# CHECK AVAILABILTY	
			$availablity_message = '';
			if(isset($_REQUEST['zip_availability']) && $_REQUEST['zip_availability']!=''){
				    $zip_availability = $_REQUEST['zip_availability'];
					$query_serv_area = mysql_query('SELECT id FROM wp_spec_service_area WHERE zip ='.$zip_availability.'');
					$count = mysql_num_rows($query_serv_area);
					$availablity_message = ($count > 0)  ? '<font color="#309b32"><strong>Service available</strong></font>' : '<font color="#FF0000">Please call us to confirm availability before purchasing.<br> Phone: 305-206-8002</font>';
			}
		    $table.='</table>
			<div class="clearfix"><br><br></div>';
			
			$table.='<div class="clearfix"><br><br></div>
					<form action="" method="post">
					<table class="table">
					
						<tr>
							<td class="col-lg-8 col-md-8">
								<div class="form-inline">
								<label class="control-label"><b>Check Availability at &nbsp;</b></label>
								<span>
									<input type="text" name="zip_availability" placeholder="Enter your Zip Code" class="form-control">
									<button class="btn btn-md btn-primary">Check</button>
								</span>
								</div>
								<div class="clearfix"></div>
								'.$availablity_message.'
								
							 </td>
							 <td class="col-lg-2 col-md-2 text-right"> Total Amount :</td>
							 <td class="col-lg-2 col-md-2 text-center">$'.$total_price.'.00</td>
							
						</tr>
					</table>
					</form>
					</div>';
								
			/*
			$table.='<br>
			<form action="" method="post">
			<table width="100%">
			<tr><td align="left"><font color="#FF0000">'.$availablity_message.'</font></td><td ></td></tr>
			<tr><td>Check Availability at &nbsp;<input placeholder="Enter your Zip Code " type="text" name="zip_availability">&nbsp;
				<input type="submit" value="Check"></td>
				<td >Total Amount :$'.$total_price.'</td></tr>
			</table>
			</form>';*/
			
			# ADDITIONAL SERVICES
		   /* $table.='<table width="145%">
						<tr><td colspan="3"><h2>Additional Services</h2></td></tr>
						<tr><td width="47%"></td><td width="9%"></td><td width="44%">
						</td></tr>
						';*/
						
			$table.='<h2>Additional Services</h2>
					<div class="clearfix"></div>';
					
			$table.='<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover">
					<th class="col-lg-3 col-md-3 text-center">Service</th>
					<th class="col-lg-5 col-md-5 text-center">Details</th>
					<th class="col-lg-2 col-md-2 text-center">Price</th>
					<th class="col-lg-2 col-md-2 text-center"></th>
					';		

			$query_cart = mysql_query('SELECT * FROM wp_spec_package WHERE type="Service"');
			if (mysql_num_rows($query_cart) > 0 )
			{
				while ($row = mysql_fetch_assoc($query_cart))
				{
					$id      	  = $row['id'];
					$name 		  = $row['name'];
					$description  = $row['description'];
					$price		  = $row['price']; 
					
					/*$params = array( 'id' => $id);
					$add_service = add_query_arg( $params, get_permalink() );
					<a href="'.$add_service.'"> Add Service</a>*/
					
					/*$table.='<tr><td>'.$name.'</td><td>$'.$price.'</td><td>
									<form action="'.get_site_url().'/list-of-specturm-orders" method="post">
									<input type="hidden" name="package" value="'.$id .'" />
									<input type="hidden" name="id" value="'.$id .'" />
									<input  type="submit" value="Add Service" name="submit" /></form>
						</td></tr>';*/
						
					$table.='<tr>
							<td class="col-lg-4 col-md-4 text-left">'.$name.'</td>
							<td class="col-lg-4 col-md-4 text-left">'.$description.'</td>
							<td class="col-lg-2 col-md-2 text-center">$'.$price.'</td>
							<td class="col-lg-2 col-md-2 text-center">
								<form action="'.get_site_url().'/list-of-specturm-orders" method="post">
									<input type="hidden" name="package" value="'.$id .'" />
									<input type="hidden" name="id" value="'.$id .'" />
								<input class="btn btn-sm btn-warning" type="submit" value="Add Service" name="submit" />
								</td>
								</form>
							</tr>';	
					
				}
			}		
			$table.='</table></div>';		
			
			/*$table.='<table width="100%">
						<tr><td width="68%">&nbsp;</td>
						<td width="17%"><a class="btn btn-lg btn-default btn-warning" href="'.get_site_url().'/order'.'">Continue Shoping</td>
						<td width="15%"><a class="btn btn-sm btn-primary" href="'.$continue_link.'">Continue</td></tr>
					</table>';*/
					
			$table.='<div class="clearfix">&nbsp;</div>
			<div class="col-lg-12 col-md-12 col-sm-12">
				
				<a class="btn btn-lg btn-warning pull-right" href="'.$continue_link.'">Continue</a>
				<a class="btn btn-lg btn-primary pull-right" href="'.get_site_url().'/order'.'">Continue Shoping</a>
			</div>
			<div class="clearfix">&nbsp;</div>
			</div>
			<div class="clearfix">&nbsp;</div> 	';	
					
					
			return $table;
		 }				
		 }
 
 
	# MY ACCOUNT 
	function user_details_func(){
		
		if($_SESSION['user_ID']==''){
			echo '<script>
						 window.location.href = "'.get_site_url().'/login"; 
				</script>';
				exit;
			}
		//error_reporting(0);
		require_once("userclass.php");
		$objUser = new userClass();
		
		require_once("paymentclass.php");
		$objPayment = new paymentClass();
		
		require_once("trackclass.php");
		$objTrack = new trackClass();
		
		require_once("packageclass.php");
		$objPackage = new packageClass();
		if(isset($_REQUEST['mark_as_completed'])){
			
			$message_to_customer	= stripslashes($_POST['message_to_customer']);
			$order_id			    = $_POST['order_id'];
			$assigned_by 			= $_POST['user_id'];
			$message_to				= $_POST['customer_id'];		
			$mail_main_body			= $message_to_customer;
			# NOTIFICATION TO CUSTMER
			# $objTrack->send_mail_track($message_to,$subject,$mail_main_body,$headers,$attachments,$assigned_by,$order_id,$mailtype='tour_completed');
			if(isset($message_to_customer)){
				$objTrack->saveMessage($assigned_by,$message_to,$order_id,$message_to_customer);
			}
			$objTrack->update_status_time($order_id,$track_status=6);
			mysql_query("UPDATE  `wp_spec_order_trac` SET  `track_status` =  '6' WHERE  `wp_spec_order_trac`.`order_id` =".$order_id.";");
			}
		if(isset($_REQUEST['shedule_photoshoot'])){ 
			$order_id			   = $_POST['order_id'];	
			$shootsheduled_message = $_POST['shootsheduled_message'];
			$message_to			   = $_POST['customer_id'];
			$assigned_by           = $_POST['user_id'];
			$shoot_date_time	   = $_POST['shoot_date_time'];
			
			//$objTrack->send_mail_track($to='sthomas@wbpro.com',$subject='test',$message='test',$headers,$attachments);
			
			
			$mail_main_body  = 'The new status is :Photoshoot Scheduled<br><br>';
			$mail_main_body .= 'Date and Time :'.$shoot_date_time.'<br><br>';
			//$objTrack->send_mail_track($message_to,$subject,$mail_main_body,$headers,$attachments,$assigned_by,$order_id,$mailtype='schedule_photoshoot');
			if(isset($shootsheduled_message)){
				$objTrack->saveMessage($assigned_by,$message_to,$order_id,$mail_main_body);
			}
			if($shoot_date_time!=''){
			mysql_query("UPDATE  `wp_spec_order_trac`  SET  `track_status` =  '3',`photoshoot_time` =  '".$shoot_date_time."' WHERE  `wp_spec_order_trac`.`order_id` =".$order_id.";");			
			$objTrack->update_status_time($order_id,$track_status=3);
			}
			
			 echo '<script>
						 setTimeout(function () {
							 window.location.href = "'.get_site_url().'/my-account/my-account"; 
						}, 0);
		
				  </script>';	
		     exit;		  
			
			
			
			}
		if(isset($_REQUEST['assign_to_designer'])){
			$assigned_designer 	   = $_POST['assigned_designer'];
			$download_link		   = $_POST['download_link']; 	
			$message_to_designer   = $_POST['message_to_designer'];
			$order_id			   = $_POST['order_id'];
			$assigned_by		   = $_POST['user_id'];
			$mail_main_body = $message_to_designer;
			# NOTIFICATION TO DESIGNER
			$objTrack->send_mail_track($assigned_designer,$subject,$mail_main_body,$headers,$attachments,$assigned_by,$order_id,$mailtype='shoot_completed');
			if(isset($mail_main_body)){
				$objTrack->saveMessage($assigned_by,$assigned_designer,$order_id,$mail_main_body);
			}
			$objTrack->assign_project($assigned_by,$assigned_designer,$order_id,$track_status=5);			
			}	
		
		if(isset($_REQUEST['send_message'])){
			$user_to_send_message = $_POST['user_to_send_message'];
			$message_to_user	  = $_POST['message_to_user'];
			$order_id			  = $_POST['order_id'];
			$user_id			  = $_POST['user_id'];
			
		/*	mysql_query("INSERT INTO  `wp_spec_messages` (
									`id` ,
									`added_by` ,
									`send_to` ,
									`track_id` ,
									`message` 
									)
									VALUES (
									NULL ,  '".$user_id."',  '".$user_to_send_message."',  '".$order_id."',  '".$message_to_user."'  
									);
									");*/

			
			$objTrack->saveMessage($user_id,$user_to_send_message,$order_id,$message_to_user);
			 echo '<script>
						 setTimeout(function () {
							 window.location.href = "'.get_site_url().'/my-account/my-account"; 
						}, 0);
		
				  </script>';	
		     exit;	
			
			}
		
		if(isset($_REQUEST['save_bill_address'])){
			$user_id = $_REQUEST['user_id'];
			$email	 = $_POST['email'];
			$city	 = $_POST['city'];
			$state	 = $_POST['state'];
			$zip	 = $_POST['zip'];
			$phone	 = $_POST['phone'];
			$address = $_POST['address'];
			$first_name = $_POST['first_name'];
			$last_name = $_POST['last_name'];
			
			$objUser->updateUserInfo($user_id,'address',$address);
			$objUser->updateUserInfo($user_id,'first_name',$first_name);
			$objUser->updateUserInfo($user_id,'last_name',$last_name);
			$objUser->updateUserInfo($user_id,'city',$city);
			$objUser->updateUserInfo($user_id,'state',$state);
			$objUser->updateUserInfo($user_id,'zip',$zip);
			$objUser->updateUserInfo($user_id,'phone',$phone);
			mysql_query("UPDATE  `wp_users` SET  `user_email` =  '".$email."' WHERE  `wp_users`.`ID` =".$user_id.";");
			}
		
		$params = array( 'logout' => "yes");
		$logout_url = add_query_arg( $params,get_permalink().'/login' );	
		
		# MANAGE ACCOUNT AREA	
	    	
		$user_id = $_SESSION['user_ID'];	 
		
		# User DATA
		$user_info = get_userdata($user_id);
		# USer Details
		
		$first_name		 = $user_info->first_name;
		$last_name		 = $user_info->last_name;
		$name 			 = $first_name.' '.$last_name;
		$email			 = $user_info->user_email;	
		$address 		 = $user_info->address;
		$city 			 = $user_info->city;
		$state			 = $user_info->state;
		$zip			 = $user_info->zip;
		
		$user_brokerage		  = $user_info->brokerage;
		$user_agent_email	  = $user_info->agent_email;
		$user_agent_name	  = $user_info->agent_name;
		$user_agent_phone	  = $user_info->agent_phone;
			
		    if($_SESSION['user_type']=='designer') {
				$user_type = 'designer';
				include('photographer_home.php');
				//include('designer_home.php');
				}
				
			else if($_SESSION['user_type']=='photographer'){
				$user_type = 'photographer';
				include('photographer_home.php');}
			else{
				$user_type = 'customer';
				include('photographer_home.php');
				//include('customer.php');
				}
			echo $html;
		 
	   }
	 
	
	# MANAGE LISTING ADDRESS 
	function listing_address_func(){
		
	     $error_msg ='';
		 $error     =0;
		 require_once("userclass.php");
		 $objUser = new userClass();
		 if(isset($_REQUEST['save_listing_address']))	 {
		 $brokerage     	= $_REQUEST['brokerage'];
		 $agent_email	    = $_REQUEST['agent_email'];
		 $agent_name		= $_REQUEST['agent_name'];
		 $agent_phone		= $_REQUEST['agent_phone'];
		 $property_address  = $_REQUEST['address'];
		 $description		= $_REQUEST['description'];
		 $unit_number       = $_REQUEST['unit_number'];
		 $sq_footage        = $_REQUEST['sq_footage'];
		 $bed_bath          = $_REQUEST['bed_bath'];
		 
		 if($_REQUEST['east'] =='on'){ $faces = 'East';}
		 if($_REQUEST['west'] =='on'){ $faces.= ',West';}
		 if($_REQUEST['north']=='on'){ $faces.= ',North';}
		 if($_REQUEST['south']=='on'){ $faces.= ',South';}
		 
		 $user_id			= $_SESSION['user_ID'];
		 if($brokerage == ''){
				 $error_msg = 'Brokerage Field is Blank';
				 $error =1;
				 }
		 if($property_address == ''){
				 $error_msg .= '<br>Property Address Field is Blank';
				 $error =1;
				 } 
		 
		 if($error_msg==''){
			 mysql_query("INSERT INTO `wp_spec_listing_address` (`id`,
																 `brokerage`,
																 `agent_email`,
																 `agent_name`,
																 `agent_phone`, 
																 `property_address`,
																 `description`, 
																 `unit_number`, 
																 `sq_footage`, 
																 `bed_bath`,
																 `faces`, 
																 `user_id`) VALUES (NULL,
																 '".$brokerage."', 
																 '".$agent_email."',
																 '".$agent_name."',
																 '".$agent_phone."',
																 '".$property_address."',
																 '".$description."', 
																 '".$unit_number."',
																 '".$sq_footage."',
																 '".$bed_bath."', 
																 '".$faces ."',
																 '".$user_id."');"); 
			$_SESSION['listing_add_id'] = mysql_insert_id();
			
			
			$objUser->updateUserInfo($user_id,'brokerage',$brokerage);
			$objUser->updateUserInfo($user_id,'agent_email',$agent_email);
			$objUser->updateUserInfo($user_id,'agent_name',$agent_name);
			$objUser->updateUserInfo($user_id,'agent_phone',$agent_phone);
			 
			 echo '<script>
						 setTimeout(function () {
							 window.location.href = "'.get_site_url().'/order-form"; 
						}, 0);
		
				  </script>';	
		     exit;		  
			
			 }
			 
		 }
		 		if($error==1){
					
				$error_msg ='<div class="alert alert-danger alert-dismissible" role="alert">
 						 <button type="button" class="close" data-dismiss="alert">
						 <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  							<strong>'.$error_msg.'</strong> 
						</div>';
					
					}
				
					$user_id			= $_SESSION['user_ID'];
					# User DATA
					$user_info = get_userdata($user_id);
					# USer Details
				
					$user_brokerage		  = $user_info->brokerage ? $user_info->brokerage : '';
					$user_agent_email	  = $user_info->agent_email ? $user_info->agent_email : '';
					$user_agent_name	  = $user_info->agent_name ? $user_info->agent_name : '';
					$user_agent_phone	  = $user_info->agent_phone ? $user_info->agent_phone : '';
					$address			  = $_POST['address'] ? $_POST['address'] : '';	
					
				
					$description		  = $_POST['description'] ? $_POST['description'] : '';	
					$unit_number		  = $_POST['unit_number'] ? $_POST['unit_number'] : '';	
					$sq_footage			  = $_POST['sq_footage'] ? $_POST['sq_footage'] : '';	
					$bed_bath			  = $_POST['bed_bath'] ? $_POST['bed_bath'] : '';	

					
						

				
		 		echo '<form action="" method="post"> <h1>Order Form</h1>
					  
					  <div class="progressbarBlock">
						<ul class="progressbar">
							<li class="stage3"><img src="'.get_template_directory_uri().'/images/steps_3.png" class="img-responsive" /></li>
						</ul>
					  </div>
					  
					  <div id="shoppingCart_Wrapper"> 
						<h2>Listing Address</h2>  
						<div class="clearfix"></div>
						<p class="text-left" align="left">Please provide the information of the property where the services will be performed.</p>
						
						<div class="clearfix"></div>
						
						
						
						'.$error_msg.'
						<div class="form-horizontal">
							<ul class="form-group">
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Brokerage :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" name="brokerage" value="'.$user_brokerage.'" class="form-control" ></span>
								</li> 
								
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Agent Email :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" value="'.$user_agent_email.'"  name="agent_email" class="form-control" ></span>
								</li> 
								
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Agent Name :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" value="'.$user_agent_name.'" name="agent_name" class="form-control" ></span>
								</li> 
								
								
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Agent Phone :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text"  value="'.$user_agent_phone.'" class="form-control" name="agent_phone"></span>
								</li> 
								
								
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Property Address :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<textarea name="address"  value="'.$address.'" class="form-control" ></textarea></span>
								</li> 
								
								
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Notes and Requests :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<textarea  class="form-control" name="description">'.$description.'</textarea></span>
								</li> 
								
								
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Unit Number :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" class="form-control" value="'.$unit_number.'" name="unit_number" ></span>
								</li> 
								
								
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Sq Footage :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" class="form-control" value="'.$sq_footage.'" name="sq_footage" ></span>
								</li> 
								
								
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12"># of Bed/Bath :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" class="form-control" value="'.$bed_bath.'" name="bed_bath"></span>
								</li> 
								
								
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Faces :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<div class="form-inline">
									
										<input type="checkbox" name="east"> East &nbsp;&nbsp;&nbsp;
										<input type="checkbox" name="west"> West &nbsp;&nbsp;&nbsp;
										<input type="checkbox" name="north"> North &nbsp;&nbsp;&nbsp;
										<input type="checkbox" name="south"> South
										
										
									
									</div>
									</span>
								</li> 
								
								
								<li class="col-lg-12 colmd-12 col-sm-12">
									  
										
										<input type="submit" class="btn btn-lg btn-warning pull-right" value="Save & Continue" name="save_listing_address">
										
								</li>
							</ul>
						</div>
				 
						
						
					 
					  </div>
					  
						<div class="clearfix">&nbsp;</div>
					   </div></form>';
					  
				/*echo '<form action="" method="post">
					  <table width="100%" border="1">
					  <tr>
						<td colspan="2"><h2>Listing Address&nbsp;</h2></td>
					
					  </tr>
					  <tr>
						<td height="62" colspan="2">Please provide the information of the property where services will be performed<br>
						<font color="red">'.$error_msg.'</font>
						
						</td>
					  </tr>
					  <tr>
						<td>Brokerage&nbsp;<font color="red">*</font><br><input type="text" name="brokerage"></td>
						<td>Agent Email&nbsp;<br><input type="text" name="agent_email"></td>
					  </tr>
					  <tr>
					   <td>Agent Name&nbsp;<br><input type="text" name="agent_name"></td>
						<td>Agent Phone&nbsp;<br><input type="text" name="agent_phone"></td>
					  </tr>
					  <tr>
						 <td>Property Address&nbsp;<font color="red">*</font><br><textarea name="address" ></textarea></td>
						<td>Other Description&nbsp;<br><input type="text" name="description"></td>
					  </tr>
					  <tr>
						 <td>Unit Number<br><input type="text" name="unit_number"></td>
						<td>Sq.Footage&nbsp;<br><input type="text" name="sq_footage"></td>
					  </tr>
					  <tr>
							<td>#bed/bath<br><input type="text" name="bed_bath"></td>
						<td>Faces<br>
						
							East<input type="checkbox" name="east">
							West<input type="checkbox" name="west">
							North<input type="checkbox" name="north">
							South<input type="checkbox" name="south">
							
						</td>  </tr>
					  <tr>
						<td>&nbsp;</td>
						<td><input type="submit" class="btn btn-lg btn-default btn-warning" value="Save & Continue" name="save_listing_address"></td>
					  </tr>
					</table>
					</form>';*/
	 
	 
	 }	
	
	# LOGIN / LOGOOT /CREATE NEW USER
	function manage_user_func(){
		  error_reporting(0);
		require_once("userclass.php");
		$objUser = new userClass();
		# LOGOUT SECTION 
		if($_REQUEST['logout'] == 'yes'){
			/*echo '<div id="shoppingCart_Wrapper">
										<div class="clearfix"></div>
										<div class="thanksHead">You have successfully logged out from your account!</div>
											<div style="margin-top:150px;" class="col-lg-12 col-md-12 col-sm12 col-xs-12 text-center">
								<!--			<a href="" class="btn btn-lg btn-primary">My Account</a>-->
											<a href="'.get_site_url().'" class="btn btn-lg btn-warning">Redirect to Home page! </a>
											</div>
										</div>';*/
			session_destroy();
			echo '<script>
						 window.location.href = "'.get_site_url().'/login"; 
				</script>';
			exit;	
			/*echo '<script>
	
					 setTimeout(function () {
						 window.location.href = "'.get_site_url().'"; 
					}, 2000);
	
				</script>';*/
			}
		# LOGIN ACTION 
		if(isset($_REQUEST['user_login'])){

			$error = ''; 
			$creds = array();
			$creds['user_login']    = $_REQUEST['user_name'];
			$creds['user_password'] = $_REQUEST['password'];
			$creds['remember'] = true;
			$user = wp_signon( $creds, false );
				if ( is_wp_error($user) ){
					$error = $user->get_error_message();
				}
				else{
					
					$_SESSION['user_login']  = $user->user_login;
					$_SESSION['user_pass']   = $user->user_pass;
					$_SESSION['user_email']  = $user->user_email;
					$_SESSION['user_ID']     = $user->ID;
					if(isset($user->caps["photographer"])){
						if($user->caps["photographer"]==1)
							$_SESSION['user_type']   = 'photographer';
					}
					else if(isset($user->caps["designer"])){
						if($user->caps["designer"]==1)
							$_SESSION['user_type']   = 'designer';
					}
					else
							$_SESSION['user_type']   = 'customer';
				$rewrite_url = (($_REQUEST['rewrite_url']) ? '/'.$_REQUEST['rewrite_url'] : '/my-account') ;	 
				echo '<script>
					 setTimeout(function () {
						 window.location.href = "'.get_site_url().$rewrite_url.'"; 
					}, 0);
	
				</script>';	
				exit;
				}
			 }
		 
		 # NEW USER CREATION
		 if(isset($_REQUEST['create_new_user'])){
			 $error  = '';
			 $user_name  = $_REQUEST['user_name']  ? $_REQUEST['user_name']  : '';
			 $user_email = $_REQUEST['user_email'] ? $_REQUEST['user_email'] : '';
			 $password   = $_REQUEST['password'];
			 $first_name = $_REQUEST['first_name'] ? $_REQUEST['first_name'] : '';
			 $last_name  = $_REQUEST['last_name']  ? $_REQUEST['last_name']  : '';
			 $address    = $_REQUEST['address']    ? $_REQUEST['address']    : '';
			 $city   	 = $_REQUEST['city']       ? $_REQUEST['city']       : '';
			 $state   	 = $_REQUEST['state']      ? $_REQUEST['state']      : '';
			 $zip   	 = $_REQUEST['zip']		   ? $_REQUEST['zip']        : '';
			 $phone   	 = $_REQUEST['phone']	   ? $_REQUEST['phone']		 : '';
			 $confirm_password = $_REQUEST['confirm_password'];
			 
			 if($user_name==''){
				 $error.= ' User filed is blank';
				 }
			 if($user_email==''){
				 $error.= ' <br> Email filed is blank';
				 }	 
			 if($password==''){
				 $error.= '<br> Password filed is blank';
				 }	 
			 if($first_name==''){
				 $error.= '<br> Name filed is blank';
				 }	
			 if($password!=	 $confirm_password){
				  $error.= '<br> Passwords do not match';
				 }
			 
			 
			 $userdata = array(
				'user_login'   => $user_name,
				'user_pass'    => $password,
				'first_name'   => $first_name,
				'last_name'	   => $last_name,
				'user_email'   => $user_email
				
			);
				/*$userdata = array(
    'user_login'  =>  'login_name',
    'user_url'    =>  $website,
    'user_pass'   =>  NULL  // When creating an user, `user_pass` is expected.
);
*/
			 if( $error ==''){
				 # CREATE A NEW USER
				 $user_id = username_exists( $user_name );
					if ( !$user_id and email_exists($user_email) == false ) {
						//$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
						// $user_id = wp_create_user( $user_name, $password, $user_email );
							$user_id = wp_insert_user( $userdata );
							$objUser->updateUserInfo($user_id,'address',$address);
							$objUser->updateUserInfo($user_id,'city',$city);
							$objUser->updateUserInfo($user_id,'state',$state);
							$objUser->updateUserInfo($user_id,'zip',$zip);
							$objUser->updateUserInfo($user_id,'phone',$phone);
		
						  # SET USER ROLE 
							 $user = new WP_User( $user_id );
							
							 $user->set_role( 'customer' );
							/* $success = '<div id="shoppingCart_Wrapper">
										<div class="clearfix"></div>
										<div class="thanksHead">New account has been created with the username:'.$user->user_login.' !</div>
											<div style="margin-top:50px;" class="col-lg-12 col-md-12 col-sm12 col-xs-12 text-center">
											
											<a href="" class="btn btn-lg btn-warning">Continue Shopping</a>
											</div>
										</div> ';	 
							mysql_query("INSERT INTO `wp_spec_user_details` (`id`,
																			 `users_id`,
																			 `fname`,
																			 `address`,
																			 `city`,
																			 `state`,
																			 `zip`,
																			 `phone`)
										VALUES (NULL, '". $user_id."', '". $full_name."',
												'".$address."', '".$city."', '".$state."', '".$zip."', '".$phone."');");	*/		
							
							$_SESSION['user_login']  = $user_name;
							$_SESSION['user_pass']   = $password;
							$_SESSION['user_email']  = $user_email;
							$_SESSION['user_ID']     = $user_id;
							if(isset($user->caps["photographer"])){
								if($user->caps["photographer"]==1)
									$_SESSION['user_type']   = 'photographer';
							}
							else if(isset($user->caps["designer"])){
								if($user->caps["designer"]==1)
									$_SESSION['user_type']   = 'designer';
							}
							else
									$_SESSION['user_type']   = 'customer';
							
							
							echo '<script>
									 window.location.href = "'.get_site_url().'/listing-address"; 
							  	 </script>';
							exit;
					} 
					else {
						 $error = ('User already exists. If you already have an account, Please login.');
						 $user_name = '';
						 echo '<script>
								 jQuery(document).ready(function(){
								 jQuery("#user_reg_check").prop("checked", true)
								register();
								});
							   </script>';
						
					}
					
			 }
			 else {
				 
				  echo '<script>
								 jQuery(document).ready(function(){
								 jQuery("#user_reg_check").prop("checked", true)
								register();
								});
							   </script>';
				 
				 }
				
			
			 
		/*echo '
            <h1>Confirmation</h1>
            <h3>user registration</h3>
            <div id="shoppingCart_Wrapper">
              <div class="clearfix"></div>
  				 <div class="thanksHead">New account has been created with the username:'.$user->user_login.' !</div>
				 <a href="" class="btn btn-sm btn-warning">Continue Shopping</a>
  				 </div>';*/
			 }
		
		 $rewrite_url = $_REQUEST['rewrite_url'];	
		 # USER LOGIN REG AREA	 
		 if($error!=''){
			$error_message = ' <div class="alert alert-danger" role="alert">'.$error.'</div>';
		 }
		 
		   $html_content = '<h1>Sign In/Sign Up</h1>
			<form name="form1" method="post" action="">
		   <input type="hidden" name="rewrite_url" value="'.$rewrite_url.'">
			<div id="shoppingCart_Wrapper">
			
			'.$error_message.'
			<div class="clearfix"></div>
			
			<div class="form-horizontal">
					<ul class="form-group">
					<li class="col-lg-12 colmd-12 col-sm-12">
						<div class="alert alert-info" style=" line-height:20px; padding:12px 15px 12px 45px; position:relative;"><i class="glyphicon glyphicon-exclamation-sign" style="font-size:25px; line-height:25px; color:#147ebf; position:absolute; left:12px; top:10px;"></i> If you already have an account, please provide your username and password. If not, check mark the option "I am a new customer" and create an account.</div>
					</li>
				
					<li class="col-lg-12 colmd-12 col-sm-12">
					<label class="col-lg-3 col-md-4 col-sm-4 col-xs-12">Username<i class="danger"> *</i> </label>
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12"><input type="text" value="'.$user_name.'" name="user_name" class="form-control" ></span>
					</li>
					<li class="col-lg-12 colmd-12 col-sm-12">
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12 col-lg-offset-3 col-md-offset-4 col-sm-offset-4">
					<input type="radio" class="widthAuto" onclick="login();" name="User_status" checked value="radio" id="User_status_0">
					&nbsp;&nbsp;I already have an account<br>
					
					<input type="radio" class="widthAuto" onclick="register();" name="User_status" value="radio" id="user_reg_check">
					&nbsp;&nbsp;I am a new customer (Sign me up now)
					
					</span>
					</li>
					<li class="col-lg-12 colmd-12 col-sm-12">
					<label class="col-lg-3 col-md-4 col-sm-4 col-xs-12">Password <i class="danger"> *</i> </label> </label>
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12"><input type="password" name="password" class="form-control" ></span>
					</li>
					<li class="col-lg-12 colmd-12 col-sm-12" id="login_new_button">
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12 col-lg-offset-3 col-md-offset-4 col-sm-offset-4">
					<input class="btn btn-lg btn-warning pull-left" type="submit" name="user_login" value="Continue">
					</span>
					</li>
					
					</ul>
					<div class="clearfix"></div>
					 <ul class="form-group" style="display:none" id="new_reg_form">
					<li class="col-lg-12 colmd-12 col-sm-12">
					<label class="col-lg-3 col-md-4 col-sm-4 col-xs-12">Confirm Password <i class="danger"> *</i> </label>
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12"><input type="password" name="confirm_password" class="form-control" ></span>
					</li>
					
					<li class="col-lg-12 colmd-12 col-sm-12">
					<label class="col-lg-3 col-md-4 col-sm-4 col-xs-12">First Name<i class="danger"> *</i></label>
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12"><input name="first_name" value="'.$first_name.'" type="text" class="form-control" ></span>
					</li>
					
					<li class="col-lg-12 colmd-12 col-sm-12">
					<label class="col-lg-3 col-md-4 col-sm-4 col-xs-12">Last Name</label>
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12"><input name="last_name" type="text" value="'.$last_name.'" class="form-control" ></span>
					</li>
					
					<li class="col-lg-12 colmd-12 col-sm-12">
					<label class="col-lg-3 col-md-4 col-sm-4 col-xs-12">Email<i class="danger"> *</i></label>
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12"><input type="text" value="'.$user_email.'" name="user_email" class="form-control" ></span>
					</li>
					
					<li class="col-lg-12 colmd-12 col-sm-12">
					<label class="col-lg-3 col-md-4 col-sm-4 col-xs-12">Phone</label>
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12"><input type="text" value="'.$phone.'"  name="phone" class="form-control" ></span>
					</li>
					 
					 
					 
				
					
					<li class="col-lg-12 colmd-12 col-sm-12">
					<label class="col-lg-3 col-md-4 col-sm-4 col-xs-12">Billing Address</label>
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12">
						
						<textarea name="address" type="text" class="form-control">'.$address.'</textarea>
					</span>
					</li>
					<li class="col-lg-12 colmd-12 col-sm-12">
					<label class="col-lg-3 col-md-4 col-sm-4 col-xs-12">City/State/Zip</label>
					<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12">
						
						<span  class="col-lg-4 col-md-4 col-sm-4 col-xs-4" style="padding-left:0px;">
						<input type="text" placeholder="City" value="'.$city.'" name="city" class="form-control" >
							
						</span>
						<span  class="col-lg-4 col-md-4 col-sm-4 col-xs-4" style="padding-left:0px !important; padding-right:0px;">
						<select name="state" class="form-control" > 
								<option value="" selected="selected">Select State</option> 
								<option value="AL">Alabama</option> 
								<option value="AK">Alaska</option> 
								<option value="AZ">Arizona</option> 
								<option value="AR">Arkansas</option> 
								<option value="CA">California</option> 
								<option value="CO">Colorado</option> 
								<option value="CT">Connecticut</option> 
								<option value="DE">Delaware</option> 
								<option value="DC">District Of Columbia</option> 
								<option value="FL">Florida</option> 
								<option value="GA">Georgia</option> 
								<option value="HI">Hawaii</option> 
								<option value="ID">Idaho</option> 
								<option value="IL">Illinois</option> 
								<option value="IN">Indiana</option> 
								<option value="IA">Iowa</option> 
								<option value="KS">Kansas</option> 
								<option value="KY">Kentucky</option> 
								<option value="LA">Louisiana</option> 
								<option value="ME">Maine</option> 
								<option value="MD">Maryland</option> 
								<option value="MA">Massachusetts</option> 
								<option value="MI">Michigan</option> 
								<option value="MN">Minnesota</option> 
								<option value="MS">Mississippi</option> 
								<option value="MO">Missouri</option> 
								<option value="MT">Montana</option> 
								<option value="NE">Nebraska</option> 
								<option value="NV">Nevada</option> 
								<option value="NH">New Hampshire</option> 
								<option value="NJ">New Jersey</option> 
								<option value="NM">New Mexico</option> 
								<option value="NY">New York</option> 
								<option value="NC">North Carolina</option> 
								<option value="ND">North Dakota</option> 
								<option value="OH">Ohio</option> 
								<option value="OK">Oklahoma</option> 
								<option value="OR">Oregon</option> 
								<option value="PA">Pennsylvania</option> 
								<option value="RI">Rhode Island</option> 
								<option value="SC">South Carolina</option> 
								<option value="SD">South Dakota</option> 
								<option value="TN">Tennessee</option> 
								<option value="TX">Texas</option> 
								<option value="UT">Utah</option> 
								<option value="VT">Vermont</option> 
								<option value="VA">Virginia</option> 
								<option value="WA">Washington</option> 
								<option value="WV">West Virginia</option> 
								<option value="WI">Wisconsin</option> 
								<option value="WY">Wyoming</option>
								</select>
						</span>
						<span  class="col-lg-4 col-md-4 col-sm-4 col-xs-4"  style="padding-right:0px;"><input name="zip" placeholder="Zip" value="'.$zip.'" type="text" class="form-control" ></span>
					</div>
					</li>
					
					
					<li class="col-lg-12 colmd-12 col-sm-12">
					
					<span class="col-lg-5 col-md-5 col-sm-6 col-xs-12 col-lg-offset-3 col-md-offset-4 col-sm-offset-4">
					
					<input class="btn btn-lg btn-warning pull-left" type="submit" name="create_new_user" value="Continue">
					</span>
					</li>
					</ul>
			</div>
			
			
			
			
			</div>
			</form>';	
		
		 return $html_content;		
		 }
	# ORDER FORM	 
	function order_form_func(){
		//error_reporting(0);
		require_once("trackclass.php");
		$objTrack = new trackClass();
		
		require_once("userclass.php");
		$objUser = new userClass();
		
		$url_myaccount = site_url( '/my-account', 'http' );
		if(isset($_REQUEST['save_bill_address'])){
			$user_id = $_REQUEST['user_id'];
	
			$email	 = $_POST['email'];
			$city	 = $_POST['city'];
			$state	 = $_POST['state'];
			$zip	 = $_POST['zip'];
			$phone	 = $_POST['phone'];
			$address = $_POST['address'];
			$first_name = $_POST['first_name'];
			$last_name = $_POST['last_name'];
			
			$objUser->updateUserInfo($user_id,'address',$address);
			$objUser->updateUserInfo($user_id,'first_name',$first_name);
			$objUser->updateUserInfo($user_id,'last_name',$last_name);
			$objUser->updateUserInfo($user_id,'city',$city);
			$objUser->updateUserInfo($user_id,'state',$state);
			$objUser->updateUserInfo($user_id,'zip',$zip);
			$objUser->updateUserInfo($user_id,'phone',$phone);
			mysql_query("UPDATE  `wp_users` SET  `user_email` =  '".$email."' WHERE  `wp_users`.`ID` =".$user_id.";");

			}
		if(isset($_REQUEST['update_listing_address'])){
			 $brokerage     	= $_REQUEST['brokerage'];
			 $agent_name	    = $_REQUEST['agent_name'];
			 $agent_email	    = $_REQUEST['agent_email'];
			 $agent_phone		= $_REQUEST['agent_phone'];
			 $property_address  = $_REQUEST['address'];
			 $description		= $_REQUEST['description'];
			 $unit_number       = $_REQUEST['unit_number'];
			 $sq_footage        = $_REQUEST['sq_footage'];
			 $bed_bath          = $_REQUEST['bed_bath'];
			 $listing_id		= $_REQUEST['listing_id'];

			 if($_REQUEST['East'] =='on'){ $faces = 'East';}
			 if($_REQUEST['West'] =='on'){ $faces.= ',West';}
			 if($_REQUEST['North']=='on'){ $faces.= ',North';}
			 if($_REQUEST['South']=='on'){ $faces.= ',South';}
			 
			$faces = ltrim($faces,',');
			 mysql_query("UPDATE  `wp_spec_listing_address` SET  `brokerage` =  '".$brokerage."',
								`agent_name`  		=  '".$agent_name."',
								`agent_email`  		=  '".$agent_email."',
								`agent_phone` 		=  '".$agent_phone."',
								`property_address`  =  '".$property_address."',
								`description` 		=  '".$description."',
								`unit_number` 		=  '".$unit_number."',
								`sq_footage` 		=  '".$sq_footage."',
								`bed_bath`			=  '".$bed_bath."',
								`faces` 			=  '".$faces."'
						  WHERE  `wp_spec_listing_address`.`id` =".$listing_id.";");
			}
		
		
		# User Details/ BILLIBG ADDRESS
		$user_info = get_userdata($_SESSION['user_ID']);
		$user_login			 = $user_info->user_login;
		$first_name			 = $user_info->first_name;
		$last_name			 = $user_info->last_name;
		$user_name 			 = $first_name.' '.$last_name ;
		$user_address 		 = $user_info->address;
		$user_city 			 = $user_info->city;
		$user_state			 = $user_info->state;
		$user_zip			 = $user_info->zip;
		$user_phone			 = $user_info->phone;
		$user_email			 = $user_info->user_email;
		
		$billing_address.='<div class="address"> 
							'.$user_name.'<br>
							'.$user_city.' '.$user_state.'<br>
		  					'.$user_zip.'<br>
							'.$user_address.'<br><br>
					 Phone: '.$user_phone.'<br>
					 Email: '.$user_email.' </div>
						  </div>';
		
		# Property Address
		 $query_prop_add = mysql_query("SELECT * FROM wp_spec_listing_address WHERE id =".$_SESSION['listing_add_id']."");
		 if (mysql_num_rows($query_prop_add) > 0 )
			{
				while ($row = mysql_fetch_assoc($query_prop_add))
				{
					$listing_id      	  = $row['id'];
					$brokerage 		  = $row['brokerage'];
					$agent_name       = $row['agent_name'];
					$agent_email	  = $row['agent_email'];
					$agent_phone	  = $row['agent_phone'];  
					$property_address = $row['property_address']; 
					$notes_requests	  = $row['description'];  
					$unit_number	  = $row['unit_number'];  
					$sq_footage	      = $row['sq_footage'];  
					$bed_bath	      = $row['bed_bath'];  
					$faces    	      = $row['faces'];  
					
					$each_faces = explode(",",$faces);
					foreach($each_faces as $face_val){
					
					
					}
					
					
					$face_val = '';
					if (in_array("East", $each_faces)) {
						$face_val.='<input type="checkbox" checked="checked" name="East"> East &nbsp;&nbsp;&nbsp;' ;
						$face_show.= 'East';
					}
					else 
						$face_val.='<input type="checkbox" name="East"> East &nbsp;&nbsp;&nbsp;' ;
					if (in_array("West", $each_faces)) {
						$face_val.='<input type="checkbox" checked="checked" name="West"> West &nbsp;&nbsp;&nbsp;' ;
						$face_show.= ', West';
					}
					else 
						$face_val.='<input type="checkbox" name="West"> West &nbsp;&nbsp;&nbsp;' ;	
						
					if (in_array("North", $each_faces)) {
						$face_val.='<input type="checkbox" checked="checked" name="North"> North &nbsp;&nbsp;&nbsp;' ;
						$face_show.= ', North';
					}
					else 
						$face_val.='<input type="checkbox" name="North"> North &nbsp;&nbsp;&nbsp;' ;
					
					if (in_array("South", $each_faces)) {
						$face_val.='<input type="checkbox" checked="checked" name="South"> South &nbsp;&nbsp;&nbsp;' ;
						$face_show.= ', South';
					}
					else 
						$face_val.='<input type="checkbox" name="South"> South &nbsp;&nbsp;&nbsp;' ;				
					
					

						
					
									/*	<input type="radio" name="east"> East &nbsp;&nbsp;&nbsp;
										<input type="radio" name="west"> West &nbsp;&nbsp;&nbsp;
										<input type="radio" name="north"> North &nbsp;&nbsp;&nbsp;
										<input type="radio" name="south"> South*/

				}
			}
/*			$property_address_show = '<div class="address"><br>
			'.$property_address.'</div></div>';*/
		 $add_for_mail=' <div class="address">';
		 $add_for_mail.= $agent_name ? '<label><strong>Agent Name: </strong>'.$agent_name .'</label><br>' : '';
		 $add_for_mail.= $brokerage ? '<label><strong>Brokerage:</strong> '.$brokerage .'</label><br>' : '';
		 $add_for_mail.= $property_address ? '<label><strong>Property Address: </strong>'.$property_address .'</label><br>' : '';
		 $add_for_mail.= $unit_number ? '<label><strong>Unit Number:</strong> '.$unit_number .'</label><br>' : '';
		 $add_for_mail.= $sq_footage ? '<label><strong>Sq Footage:</strong> '.$sq_footage .'</label><br>' : '';
		 $add_for_mail.= $bed_bath ? '<label><strong># of Bed/Bath:</strong> '.$bed_bath .'</label><br>' : '';
		 $add_for_mail.= $faces ? '<label><strong>Faces:</strong> '.$faces .'</label><br>' : '';
		 
		 $add_for_mail 			= $add_for_mail.'</div>';
		
		 
		 
		$property_address_show =' <div class="address"><table width="100%">';
		$property_address_show.= $agent_name ? '<tr><td width="35%"> <strong>Agent Name: </strong></td><td width="1%"></td><td width="65%">'.$agent_name .'</td></tr>' : '';
		$property_address_show.= $brokerage ? '<tr><td><strong>Brokerage:</strong></td><td></td><td> '.$brokerage .'</td></tr>' : '';
		$property_address_show.= $property_address ? '<tr><td><strong>Property Address: </strong></td><td></td><td>'.$property_address .'</td></tr>' : '';
		$property_address_show.= $unit_number ? '<tr><td><strong>Unit Number:</strong></td><td></td><td> '.$unit_number .'</td></tr>' : '';
		$property_address_show.= $sq_footage ? '<tr><td><strong>Sq Footage:</strong></td><td></td><td> '.$sq_footage .'</td></tr>' : '';
		$property_address_show.= $bed_bath ? '<tr><td><strong># of Bed/Bath:</strong></td><td></td><td> '.$bed_bath .'</td></tr>' : '';
		$property_address_show.= $faces ? '<tr><td><strong>Faces:</strong></td><td></td><td> '.ltrim($face_show,',').'</td></tr>' : '';
		$property_address_show.= $agent_phone ? '<tr><td><strong>Agent Phone:</strong></td><td></td><td> '.$agent_phone .'</td></tr>' : '';
		$property_address_show.= $agent_email ? '<tr><td><strong>Agent Email: </strong></td><td></td><td>'.$agent_email .'</td></tr>' : '';
		$property_address_show.= $notes_requests ? '<tr><td colspan="3"  align="left" valign="top"><strong>Notes and Requests: </strong></td></tr><tr><td colspan="3" align="left" valign="top">'.$notes_requests .'</td></tr>' : '';
		$property_address_show.='</table></div>';
		
		# PAYMENT ACTION
		if(isset($_REQUEST['pay_now'])){
			$query = mysql_query("SELECT * FROM  `wp_spec_authorise`");
			while ($row = mysql_fetch_array($query))
						{
							$field = $row['name'];
							$$field = $row['value'];
						}
			$amount 		= $_REQUEST['total_value'];
			$card_number	= $_REQUEST['card_number'];
			$user_id 		= $_SESSION['user_ID'];
			$total_amount	= $_REQUEST['total_amount'];
			$exp_moth		= $_REQUEST['exp_moth'];
			$exp_year		= $_REQUEST['exp_year'];
			$exp_date		= $exp_moth.$exp_year;
			
			// By default, this sample code is designed to post to our test server for
			// developer accounts: https://test.authorize.net/gateway/transact.dll
			// for real accounts (even in test mode), please make sure that you are
			// posting to: https://secure.authorize.net/gateway/transact.dll
			 #$post_url = "https://test.authorize.net/gateway/transact.dll";
			
			$post_values = array(
				
				// the API Login ID and Transaction Key must be replaced with valid values
				"x_login"			=> $x_login,
				"x_tran_key"		=> $x_tran_key,
			
				"x_version"			=> $x_version,
				"x_delim_data"		=> $x_delim_data,
				"x_delim_char"		=> "|",
				"x_relay_response"	=> $x_relay_response,
			
				"x_type"			=> $x_type,
				"x_method"			=> $x_method,
				"x_card_num"		=> $card_number,
				"x_exp_date"		=> $exp_date,
			 
				"x_amount"			=> $amount,
				"x_description"		=> "CC Payment",
			
				"x_first_name"		=> $first_name,
				"x_last_name"		=> $last_name,
				"x_address"			=> $user_address,
				"x_state"			=> $user_state,
				"x_zip"				=> $user_zip
				// Additional fields can be added here as outlined in the AIM integration
				// guide at: http://developer.authorize.net
			);
			
			// This section takes the input fields and converts them to the proper format
			// for an http post.  For example: "x_login=username&x_tran_key=a1B2c3D4"
			$post_string = "";
			foreach( $post_values as $key => $value )
				{ $post_string .= "$key=" . urlencode( $value ) . "&"; }
			$post_string = rtrim( $post_string, "& " );
			
			// The following section provides an example of how to add line item details to
			// the post string.  Because line items may consist of multiple values with the
			// same key/name, they cannot be simply added into the above array.
			//
			// This section is commented out by default.
			/*
			$line_items = array(
				"item1<|>golf balls<|><|>2<|>18.95<|>Y",
				"item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>Y",
				"item3<|>book<|>Golf for Dummies<|>1<|>21.99<|>Y");
				
			foreach( $line_items as $value )
				{ $post_string .= "&x_line_item=" . urlencode( $value ); }
			*/
			
			// This sample code uses the CURL library for php to establish a connection,
			// submit the post, and record the response.
			// If you receive an error, you may want to ensure that you have the curl
			// library enabled in your php configuration
			$request = curl_init($post_url); // initiate curl object
				curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
				curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
				curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
				curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
				$post_response = curl_exec($request); // execute curl post and store results in $post_response
				// additional options may be required depending upon your server configuration
				// you can find documentation on curl options at http://www.php.net/curl_setopt
				curl_close ($request); // close curl object
			
			// This line takes the response and breaks it into an array using the specified delimiting character
			$response_array = explode($post_values["x_delim_char"],$post_response);
			
			
			
			// The results are output to the screen in the form of an html numbered list.
			
			/*echo "<OL>\n";
			foreach ($response_array as $value)
			{
				echo "<LI>" . $value . "&nbsp;</LI>\n";
			}
			echo "</OL>\n";*/
			
			// individual elements of the array could be accessed to read certain response
			// fields.  For example, response_array[0] would return the Response Code,
			// response_array[2] would return the Response Reason Code.
			// for a list of response fields, please review the AIM Implementation Guide
			
			# CALL BACK STATUS UPDATE
	
			
			$payment_status  = $response_array[0];
			$payment_message = $response_array[3];
								
  			$listing_add_id	 =$_SESSION['listing_add_id'];
			
			foreach(($_SESSION['spec_cart']) as $package){
				$package_ids = $package_ids.'-'.$package;
				}
			$query_count = mysql_query('SELECT id FROM wp_spec_checkout WHERE listing_add_id ='.$listing_add_id.'');
			
			$payment_time = time();
			if (mysql_num_rows($query_count) == 0 )		{						
				mysql_query("INSERT INTO `wp_spec_checkout` (`id`, 
															 `user_id`,
															 `listing_add_id`,
															 `package_ids`,
															 `total_amount`, 
															 `payment_status`,
															 `payment_message`,
															 `payment_time`)
												VALUES (NULL, '".$user_id ."',
															  '".$listing_add_id."',	
															  '".ltrim($package_ids,'-')."',
															  '".$total_amount."',
															  '".$payment_status."', 
															  '".$payment_message."',
															  '".$payment_time."');");
				$order_id 		= mysql_insert_id();
				$_SESSION['order_id'] = $order_id;
				
			}
			else 
			$order_id = $_REQUEST['order_id'];
			# CALL BACK REPLAY
		
			
			 # Success
			 $content_header= '<div class="entry-content">
							<div align="left" class="show_print"><img src="'.get_template_directory_uri().'/images/logo.png" /></div>
							<h1>Order Form</h1>
							<div id="shoppingCart_Wrapper">
							  <div class="clearfix"></div>
				  				 <div class="thanksHead">Thank you for using Spectrum Real Estate Photography!</div>
							  <div class="col-lg-12 col-md-12 col-sm-12">
							  <div class="itemPurchasedHead">Items Purchased</div>
							  <div class="col-lg-12 text-center" align="center">';
			 # Items Purchased 
             $content_body    ='<div class="col-lg-7" style="float:none; margin:0 auto;">
				<table class="table table-bordered" >
                	<tbody>';
					$total_price = 0;
					foreach(($_SESSION['spec_cart']) as $package){
					$query_cart = mysql_query('SELECT * FROM wp_spec_package WHERE id ='.$package.'');
					if (mysql_num_rows($query_cart) > 0 )
					{
						while ($row = mysql_fetch_assoc($query_cart))
						{
							$id      	  = $row['id'];
							$name 		  = $row['name'];
							$description  = $row['description'];
							$terms		  = $row['terms'];  
							$price		  = $row['price']; 
							$total_price  = $total_price + $price;
						}
					}
					$content_body.='<tr>
                        		<td class="col-lg-9 text-left">'.$name.'</td><td class="col-lg-4 text-right">$'.$price.'</td>
                       		  </tr>';
				  }
					
                   $content_body.='<tr>
                        	<td class="col-lg-9 text-right">Total</td><td class="col-lg-4 text-right">$'.$total_price.'</td>
                        </tr>';
						
                  $content_body.='</tbody>
                </table>
                </div>
              </div>';
			  
             $content_address ='<div class="clearfix"></div>
         	  <div class="col-lg-8" id="contact_DetailsBlock" style="float:none; margin:0 auto;">
				  <div class="col-lg-6"> 
							<div class="addressBlock">
							  <h4>Billing Address 
							  <!--<img id="editBillAddress" class="pull-right" src=""  data-toggle="modal" data-target=".bs-editBillAddress-modal-md">--></h4>
							  '.$billing_address.'
							</div>
						   <div class="col-lg-6">
							  <div class="addressBlock">
							  <h4>Property Address<!-- <img  id="editPropAddress"  class="pull-right" src="">--></h4>
							 '.$property_address_show.'
						   </div>
					  <div class="clearfix"></div> 
				  </div><div class="clearfix"></div> 
              </div>
			  ';
			 $content_bottom  =' 
              <div class="clearfix">&nbsp;</div>
              <div class="contactMsg">Photographer will contact you within 24 hrs</div>
              <div class="col-lg-12 col-md-12 col-sm-12 text-center delete_print">
                <a href="'.$url_myaccount.'"  class="btn btn-lg btn-primary ">My Account</a>
                <button  class="btn btn-lg btn-warning" onClick="window.print()">Print</button>
              </div>';
			  
			 $content_footer  ='  
              <div class="clearfix">&nbsp;</div> 
            </div>
            <div class="clearfix">&nbsp;</div>
          </div>';
		  	 
			 # MAIL CONTENT
			 $mail_main_body = ' <div style="color:rgb(34,34,34);font-family:arial,clean,sans-serif;text-transform:uppercase;font-size:14px;border-bottom-width:1px;border-bottom-style:dotted;border-bottom-color:rgb(15,15,15);padding-bottom:15px">
									<p style="margin:0pt;font-weight:bold">
									  <label>ORDER NUMBER:</label>
									  &nbsp;#'.$order_id.'</p>
									<p style="margin:0pt;color:rgb(109,110,113)">
									  <label>ORDER DATE:</label>
									 '.date("d/m/Y").'</p>
									<p style="margin:0pt;color:rgb(109,110,113)">
									  <label>STATUS:</label>
									  &nbsp;Pending</p>
								  </div>
							   <div style="color:rgb(34,34,34);font-family:arial,clean,sans-serif;font-size:12px;border-bottom-width:1px;border-bottom-style:dotted;border-bottom-color:rgb(15,15,15);padding-bottom:11px;margin:15px 0pt">
								<table style="width:896px">
								  <tbody>
									<tr>
									  <td style="vertical-align:top;padding:0pt 10px 0pt 0pt"><h3 style="font-size:14px">Billing address</h3>
										<div><strong>'.$user_name.'&nbsp;<br>
										  </strong>'.$user_address.'&nbsp;<br>
										  '.$user_state	.'&nbsp;<br>
										  '.$user_zip.' '.$user_city.'&nbsp;<br>
										 
										  <span style="color:rgb(149,149,149);margin-top:3px;display:block;font-size:11px">
										 
										  Mobile phone:&nbsp;<a href="#" >'.$user_phone.'</a>&nbsp;<br>
										   Email:<span>'.$user_email.'</span>&nbsp;<br>
										
										  
										  </span></div></td>
									  <td style="vertical-align:top"><h3 style="font-size:14px">Service Address</h3>
										'.$add_for_mail.'
										<span style="color:rgb(149,149,149);margin-top:3px;display:block;font-size:11px">
										
										Mobile phone:&nbsp;<a href="#">'.$agent_phone .'</a>&nbsp;<br>
										Email:<span>'.$agent_email.'</span&nbsp;<br>
										</span></td>
									</tr>
								
								  </tbody>
								</table>
							  </div>';			
							  
		   

			
			
			# $response_array[0] = 1; 
			 if($response_array[0] == 1){
					# DISPLAY SUCCESS PAGE/PRINT RECIPT
					echo $content 		= $content_header.$content_body.$content_address.$content_bottom.$content_footer;
					# UPDATE PAYMENT STATUS AS SUCCESS
					mysql_query("UPDATE  `wp_spec_checkout` SET  `payment_status` =  '1' WHERE  `wp_spec_checkout`.`id` =".$order_id.";");
					$objTrack->assign_project($assigned_by=1,$assigned_to=1,$order_id,$track_status	= 1);
					$message  = 'We will be contacting you within 24 hours to schedule your photo shoot.';
					$objTrack->saveMessage($assigned_by=1,$user_id,$order_id,$message);
				
					# ORDER CONFIRMATION MAIL	
						$content_mail	= $content_body.$content_address.$content_footer;												
						$objTrack->send_mail_track($user_id,$subject,$mail_main_body,$headers,$attachments,$from,$order_id,$mailtype='order_confirmation');
					# CART SESSION RESET
						unset($_SESSION['spec_cart']);
						unset($_SESSION['order_id']);
					//$content_mail = 'You have successfully completed your payment.<br><br>';
					//$content_mail .= 'Total amount payed  :<strong>$'.$total_price.'</strong>';;
					//$objTrack->send_mail_track($user_id,$subject,$content_mail,$headers,$attachments,$from,$order_id,$mailtype='payment_confirmation');
					exit;
				}
			else{
				//$content_mail  = '';
				$message	   = 'We are unable to process the payment,'.$response_array[3];
				$content_error = '<br><br> <div class="alert alert-danger" role="alert">'.$message.'</div>';
				//$content_mail .= $message.'<br><br>Total amount  :<strong>$'.floatval($total_price).'</strong>';
				//$objTrack->send_mail_track($user_id,$subject,$content_mail,$headers,$attachments,$from,$order_id,$mailtype='payment_confirmation');
				}
			}
		
	
		# ORDER COMPLETE FORM
		  $table =' <h1>Order Form</h1>
					<div class="progressbarBlock">
					  <ul class="progressbar">
						<li class="stage4"><img src="'.get_template_directory_uri().'/images/steps_4.png" class="img-responsive" /></li>
					  </ul>
					</div>
					<form action="" method="post">
		  			 <div id="shoppingCart_Wrapper">
            		 <h2>Summary and Payment</h2>
             		 <div class="clearfix"></div>
            	 	 <div class="table-responsive">
             	 	  <table class="table table-striped table-hover">
                	  <tr>
                    <th class="col-lg-8 col-md-8">Package Name</th>
                    <th class="col-lg-2 col-md-2 text-center"></th>
                    <th class="col-lg-2 col-md-2 text-center">Price</th>
                  </tr>';
		
		
					$total_price = 0;
					if($_SESSION['spec_cart']==''){
					
					echo '<script>
						 window.location.href = "'.get_site_url().'/order"; 
					</script>';
					exit;
					
					}
					foreach(($_SESSION['spec_cart']) as $package){
					$query_cart = mysql_query('SELECT * FROM wp_spec_package WHERE id ='.$package.'');
					if (mysql_num_rows($query_cart) > 0 )
					{
						while ($row = mysql_fetch_assoc($query_cart))
						{
							$id      	  = $row['id'];
							$name 		  = $row['name'];
							$description  = $row['description'];
							$terms		  = $row['terms'];  
							$price		  = $row['price']; 
							$total_price  = $total_price + $price;
							
						}
					}
					# LINK FOR REMOVE ITEM
					$params = array( 'listorders' => "true",'rm'=>$id );
					$item_remove = add_query_arg( $params, get_permalink() );	
					//$table .='<tr><td>'.$name.'</td><td></td><td>$'.$price.'</td></tr>';	
					
					$table .='<tr>
                    <td>'.$name.'</td>
                    <td class="col-lg-2 col-md-2 text-center"></td>
                    <td class="col-lg-2 col-md-2 text-center">$'.$price.'</td>
                  </tr>';
					
				  }
		  $table.='
                </table>
                <div class="clearfix"><br>
                  <br>
                </div>
				 <table class="table">
                  <tr>
                    <td class="col-lg-8 col-md-8"></td>
                    <td class="col-lg-2 col-md-2 text-right"> <input type="hidden" name="total_amount" value="'.$total_price.'">Total Amount :</td>
                    <td class="col-lg-2 col-md-2 text-center">$'.$total_price.'.00</td>
                  </tr>
				  
                </table>
				 </div>'.$content_error;
		
		 # BILLING ADDRESS / PROPERT ADDRESS
		 $table.='<div class="clearfix">&nbsp;</div>
              <div class="col-lg-12 col-md-12 col-sm-12">
                <div class="addressBlock col-lg-6 col-md-6 col-sm-6 col-xs-12">
                  <h4>Billing Address 
				  <img  id="editPropAddress"  class="pull-right" src="'.get_template_directory_uri().'/images/edit_icon.png"   data-toggle="modal" data-target=".bs-editPropAddress-modal-md">
				  </h4>';
				
				
			   $table.= $billing_address;	
               $table.=' <div class="addressBlock col-lg-6 col-md-6 col-sm-6 col-xs-12">
                  <h4>Property Address <img id="editBillAddress" class="pull-right" src="'.get_template_directory_uri().'/images/edit_icon.png"  data-toggle="modal" data-target=".bs-editBillAddress-modal-md"></h4>'.$property_address_show.'
              </div>
              <div class="clearfix">&nbsp;</div>

			   <!-- CC SETTINGS -->
               			  
		      <div class="col-lg-12 col-md-12 col-sm-12">
				<input type="hidden" name="order_id" value="'.$_SESSION['order_id'].'">
				<a href="#payment_top"   class="btn btn-lg btn-warning pull-right" onclick="pay_now_show();">Continue with Payment</a>
				<a class="btn btn-lg btn-primary pull-right" href="'.get_site_url().'/order'.'">Continue Shopping</a>
              </div>
              <div id="payment_top" class="clearfix">&nbsp;</div>
              <div class="clearfix"></div>
              <div class="paymentBlock" id="paymentBlock" style="display:none"> <h3>Payment</h3>
			 <p class="text-left"> Please enter your credit card information.</p>
<ul class="form-group col-lg-4 col-md-4 col-sm-6 col-xs-12">
					<li class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    	<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Name on Card</label>
                        <span class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><input type="text" class="form-control"></span>
                    </li> 
                	<li class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    	<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Card Number<input type="hidden" name="total_value" value="'.$total_price.'"></label>
                        <span class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><input name="card_number" type="text" class="form-control"></span>
                    </li> 
                	<li class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
                    	<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Expiration Date</label>
                        <span class="col-lg-5 col-md-5 col-sm-5 col-xs-12"><select class="form-control" name="exp_moth">
							<option value="01">01</option>
							<option value="02">02</option>
							<option value="03">03</option>
							<option value="04">04</option>
							<option value="05">05</option>
							<option value="06">06</option>
							<option value="07">07</option>
							<option value="08">08</option>
							<option value="09">09</option>
							<option value="10">10</option>
							<option value="11">11</option>
							<option value="12">12</option>
							
						   </select></span>   <span class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
						   <select class="form-control" name="exp_year">
							<option value="14">2014</option>
							<option value="15">2015</option>
							<option value="16">2016</option>
							<option value="17">2017</option>
							<option value="18">2018</option>
							<option value="19">2019</option>
							<option value="20">2020</option>
							<option value="21">2021</option>
							<option value="22">2022</option>
							<option value="23">2023</option>
							<option value="24">2024</option>
							<option value="25">2025</option>
							<option value="26">2026</option>
							<option value="27">2027</option>
							<option value="28">2028</option>
							<option value="29">2029</option>
							<option value="30">2030</option>
							<option value="31">2031</option>
							<option value="32">2032</option>
							<option value="33">2033</option>
							<option value="34">2034</option>
						   </select></span>
                    </li> 
                	<li class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                    	<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">CVV</label>
                        <span class=" col-lg-9 col-md-9 col-sm-9 col-xs-9">

						<input style="text-align:center" type="text" class="form-control"></span>
						 <!-- <span class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
						<img class="pull-left" src="'.get_template_directory_uri().'/images/cvv_icon.png" alt="CVV"/></span> -->
                    </li> 
                	
                   	<li class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
						<input class="btn btn-lg btn-warning pull-left col-lg-4 col-md-4 col-sm-4 col-xs-4" type="submit" name="pay_now" value="Pay">
             		</li>
                   
                 </ul>
              </div>
              </div>
              <div class="clearfix">&nbsp;</div>
              </div> 		
		 	 </form>
				
			   <!-- PROPERTY ADDRESS EDIT -->	
			   <div id="editBillAddress-modal"  class="modal fade  bs-editBillAddress-modal-md" tabindex="-1" role="dialog">
			  <div class="modal-dialog">
				<div class="modal-content">
				  <div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
					<h4 class="modal-title">Edit Property Address</h4> 
				  </div><form action="" method="post">
				  <div class="modal-body">
					<div class="form-horizontal">
					<input type="hidden" name="listing_id" value="'.$listing_id .'">
						<ul class="form-group">
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Brokerage :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" name="brokerage" value="'.$brokerage.'" class="form-control" ></span>
								</li> 
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Agent Email :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text"  name="agent_email" value="'.$agent_email.'" class="form-control" ></span>
								</li> 
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Agent Name :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" name="agent_name" value="'.$agent_name.'" class="form-control" ></span>
								</li> 
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Agent Phone :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" class="form-control" value="'.$agent_phone.'" name="agent_phone"></span>
								</li> 
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Property Address :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<textarea name="address" class="form-control" >'.$property_address.'</textarea></span>
								</li> 
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Notes and Requests:</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<textarea  class="form-control" name="description">'.$notes_requests.'</textarea></span>
								</li> 
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Unit Number :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" class="form-control" value="'.$unit_number.'"name="unit_number" ></span>
								</li> 
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Sq Footage :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" class="form-control" value="'.$sq_footage.'" name="sq_footage" ></span>
								</li> 
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12"># of Bed/Bath :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<input type="text" class="form-control" value="'.$bed_bath.'" name="bed_bath"></span>
								</li> 
								<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
									<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Faces :</label>
									<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<div class="form-inline">
										'.$face_val.'
									</div>
									</span>
								</li> 
							</ul>
						</div>
				  </div>
				  <div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					<input type="submit" class="btn btn-primary" value="Save changes" name="update_listing_address" > 
				  </div></form>	
				</div><!-- /.modal-content -->
			  </div><!-- /.modal-dialog -->
			</div>

			  <!-- BILLING ADDRESS EDIT-->	
				 <div id="editPropAddress-modal"  class="modal fade  bs-editPropAddress-modal-md" tabindex="-1" role="dialog" aria-hidden="true">
				  <div class="modal-dialog">
					<div class="modal-content">
					  <div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
						<h4 class="modal-title">Edit Billing Address</h4>
					  </div>
					  <form name="" method="post" action="">
					  <input type="hidden" value="'.$_SESSION['user_ID'].'" name="user_id">
					  <div class="modal-body">
						 <div class="form-horizontal">
								<ul class="form-group">
									
									<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
										<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">First Name :</label>
										<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
										<input type="text" name="first_name" value="'.$first_name.'" class="form-control" ></span>
									</li> 
									
									<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
										<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Last Name :</label>
										<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
										<input type="text" name="last_name" value="'.$last_name.'" class="form-control" ></span>
									</li> 
									
									<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
										<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">City :</label>
										<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
										<input type="text" name="city" value="'.$user_city.'" class="form-control" ></span>
									</li> 
									
									<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
										<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">State :</label>
										<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
										<input type="text" name="state" value="'.$user_state.'" class="form-control" ></span>
									</li> 
									<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
										<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Zip :</label>
										<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
										<input type="text" name="zip" value="'.$user_zip.'" class="form-control" ></span>
									</li> 
									<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
										<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Phone :</label>
										<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
										<input type="text" name="phone" value="'.$user_phone.'" class="form-control" ></span>
									</li> 
									<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
										<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Email :</label>
										<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
										<input type="text" name="email" value="'.$user_email	.'" class="form-control" ></span>
									</li> 
									<li class="col-lg-6 colmd-6 col-sm-6 col-xs-12">
										<label class="col-lg-12 col-md-12 col-sm-12 col-xs-12">Address :</label>
										<span class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
										<textarea name="address" class="form-control" >'.$user_address.'</textarea></span>
									</li>
								</ul>
							</div>
					  </div>
					  <div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
						<input type="submit" name="save_bill_address" value="Save changes" class="btn btn-primary">
					  </div>
					  </form>
					</div><!-- /.modal-content -->
				  </div><!-- /.modal-dialog -->
				</div>
				';
		echo $table;		
		}		

	/**
	 * Redirect user after successful login.
	 *
	 * @param string $redirect_to URL to redirect to.
	 * @param string $request URL the user is coming from.
	 * @param object $user Logged user's data.
	 * @return string
	 */
	function my_login_redirect( $redirect_to, $request, $user ) {
		//is there a user to check?
		global $user;
		if ( isset( $user->roles ) && is_array( $user->roles ) ) {
			//check for admins
			if ( in_array( 'administrator', $user->roles ) ) {
				// redirect them to the default place
				return $redirect_to;
			} else {
				return home_url();
			}
		} else {
			return $redirect_to;
		}
	}


	/* if(isset($_REQUEST['submit'])){
		 
		 
	$wp_session = WP_Session::get_instance();
	$data = $session->toArray();
	$package_id = $_POST['package'];
	$wp_session['package']= $package_id;
	
	//array_push($_SESSION['package'],$_POST['package']);
/*	$package_id = array();
	$package_id = $wp_session['package'];
	$package_id[] = $_POST['package'];
	if(!in_array($_POST['package'],current($package_id)))
	$wp_session['package']= $package_id;
    sizeof($wp_session['package']);*/
	
	//exit;

/*$table = '<style>
			table {
				width:100%;
			}
			table, th, td {
				border: 1px solid black;
				border-collapse: collapse;
			}
			th, td {
				padding: 5px;
				text-align: left;
			}
			table#t01 tr:nth-child(even) {
				background-color: #eee;
			}
			table#t01 tr:nth-child(odd) {
			   background-color:#fff;
			}
			table#t01 th	{
				background-color: black;
				color: white;
			}
			</style>

<table  border="1" style="width:100%">
				  <tr><td>Package Name </td><td>Remove Items</td><td>Price</td></tr>';
				  
				//  for($i=0;$i<= count($wp_session['package']) ;$i++){
					foreach(current($wp_session['package']) as $package){
					
						   $table .='
  				  <tr><td>'.$package[$i].'</td><td><a href="">Remove</a></td><td></td></tr>';
						  
					
				  
				 
				  }

		  $table.='  </table><br>
			
			<table><tr><td><a href="?page_id=12">Continue Shoping</a></td><td>Continue</td></tr></table>';
			return $table;

	
	}
	
	 
	 }*/?>